<?php
namespace App\Api\V1\Models;

use Illuminate\Database\Eloquent\Model;

class Coupon extends Model
{



    protected $table = 'coupon';
    public $timestamps = false;
//    const CREATED_AT = 'give_begin_time';
//    const UPDATED_AT = 'give_end_time';
//    const CREATED_AT = 'use_begin_time';
//    const UPDATED_AT = 'use_begin_time';
/*增加优惠卷*/
    public function addCouponItem($request)
    {

           $ds=[

               'name'=>'六一快乐',
               'description'=>'活动描述',
               'guide'=>'//careyshop.cn',
               'type'=>'2',
               'money'=>'100',
               'quota'=>'1000',
               'category'=>'[1,2,3]',
               'exclude_category'=>'[5,6,7]',
               'level'=>'[]',
               'frequency'=>'1',
               'give_num'=>'2000',

               'give_begin_time'=>'0',
               'give_end_time'=>'0',
               'use_begin_time'=>'0',
               'use_end_time'=>'0',
               'status'=>'1',
               'is_invalid'=>'0'

           ];


        $this->name = $ds['name'];
        $this->description = $ds['description'];
        $this->guide= $ds['guide'];
        $this->type = $ds['type'];
        $this->money = $ds['money'];
        $this->quota = $ds['quota'];
        $this->category= $ds['category'];
        $this->exclude_category = $ds['exclude_category'];
        $this->level= $ds['level'];
        $this->frequency = $ds['frequency'];
        $this->give_num= $ds['give_num'];
        $this->give_begin_time = $ds['give_begin_time'];
        $this->give_end_time= $ds['give_end_time'];
        $this->use_begin_time = $ds['use_begin_time'];
        $this->use_end_time= $ds['use_end_time'];
        $this->status = $ds['status'];
        $this->is_invalid = $ds['is_invalid'];
       if ($this->save()) {
            return $this->toArray();
        }
        return false;


  	}
  	/*编辑优惠卷*/
     public function setCouponItem($ds)
     {
         $ds=[
             'name'=>'测试修改是否成功',
             'description'=>'活动描述',
             'guide'=>'//careyshop.cn',
             'type'=>'2',
             'money'=>'100',
             'quota'=>'1000',
             'category'=>'[1,2,3]',
             'exclude_category'=>'[5,6,7]',
             'level'=>'[]',
             'frequency'=>'1',
             'give_num'=>'2000',
             'give_begin_time'=>'0',
             'give_end_time'=>'0',
             'use_begin_time'=>'0',
             'use_end_time'=>'0',
             'status'=>'1',
             'is_invalid'=>'0'
         ];
         $res = coupon::where('coupon_id',14)->update($ds);
          return false;


     }
     /*获取优惠卷列表*/
    public function getCouponList($request)
    {
        $res = coupon::get()->toarray();

        return json_encode($res);
    }
    /*获取一张优惠卷*/
    public function getCouponItem($td)
    {
        $df=coupon::where('coupon_id',17)->first()->toarray();

        return $df;
    }
    /*删除优惠卷*/
    public function delCouponList($request)
    {
        $tt=coupon::where('coupon_id', 14)->delete();
        if($tt){
            return true;
        }
    }
}
